<?php
namespace App\HttpController\Admin;

use App\HttpController\AdminBase;
use EasySwoole\Validate\Validate;
use App\Model\MemberLevel as MemberLevelModel;
class Memberlevel extends AdminBase
{

    /**
     * 用户层级
     * @return MemberLevelModel
     */
    public function getMemberLevelModel(){
        return new MemberLevelModel();
    }

    public function index()
    {

        if($this->isPost()){
            $where=array();
            $title=$this->postParam('title');
            if(!empty($title)){
                $where["title|like"]=array("like",'%'.$title.'%');
            }
            $type=$this->postParam("type");
            if(!empty($type)){
                $where["type"]=$type;
            }
            return $this->writePageJson('数据列表',$this->getMemberLevelModel()->getPageAll($this->getMemberLevelModel()->analysisWhere($where)));
        }
       return $this->fetch('index');
    }

    public function add(){
        return $this->fetch('add');
    }

    public function edit(){
        return $this->fetch('edit');
    }
    /**
     * 提交参数验证
     * @param string|null $action
     * @return Validate|null
     */
    protected function getValidateRule(?string $action): ?Validate
    {
        $validate = null;
        if ($this->isPost()) {
            switch ($action) {
                case 'classsave';  //操作方法
                    $validate = new Validate();
                    $validate->addColumn('pname', '分类名称')->required('不能为空');
                    break;
            }
        }
        return $validate;
    }
}